//
//$Id: grids.h 649 2011-02-18 18:30:44Z andrew.tsyganov $

#pragma once

#include "sets.h"
#include "types.h"

const size_t kDefaultGridsCapacity = 2048;

class Grid
{
private:
    Subset rows_, columns_;
public:
    inline size_t size() { return rows_.size() * columns_.size(); }
    inline void clear() { rows_.remove(); columns_.remove(); }

    inline Subset const& get_Rows() const { return rows_; }
    inline Subset const& get_Columns() const { return columns_; }

    inline void init(Subset const& r, Subset const& c) { rows_ = r; columns_ = c; }
    inline void set_Rows(Subset const& r) { rows_ = r; }
    inline void set_Columns(Subset const& c) { columns_= c; }

    std::string to_String(Brackets_Type const bt = BRACES, int const add = 0) const;

    unsigned char* serialize(unsigned& len) const;
    void deserialize(unsigned char* buf);
};

bool operator <=(Grid const& lhs, Grid const& rhs);
bool operator ==(Grid const& lhs, Grid const& rhs);

void PrintGridsTXT(std::ostream& os, std::vector<Grid> const& vg);
void PrintGridsLaTeX(std::ostream& os, std::vector<Grid> const& vg);
void PrintGridsSetTXT(std::ostream& os, std::vector<Grid> const& vg, Subset const& s);
void PrintGridsSetLaTeX(std::ostream& os, std::vector<Grid> const& vg, Subset const& s);

bool MakeGridByRows(Bool_Matrix const& matr, Subset const& rs, Grid& g);
bool MakeGridByColumns(Bool_Matrix const& matr, Subset const& cs, Grid& g);

void FindGridsSEQ(Bool_Matrix const& matr, std::vector<Grid>& grids);

//EOF!
